/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年12月4日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20191204_fastsort
 * @Desc
 * @author 52489
 * @date 2019年12月4日
 * @Version V1.0
 */
public class A20191204_fastsort {

    public static void main(String[] args) {
        int[] nums = { 10, 6, 3, 8, 33, 27, 66, 9, 7, 88, 20 };
        int start = 0;
        int end = nums.length - 1;
        System.out.println(Arrays.toString(fastSort(nums, start, end)));
    }

    public static int[] fastSort(int[] num, int start, int end) {
        if (start != end) {
            int left = start;
            int right = end;
            int tmp = num[left];
            // 第一个标志位排序左边是小于标志位，右边是大于标志位；
            while (left != right) {
                while (left != right && num[right] > tmp) {
                    right--;
                }
                num[left] = num[right];
                System.out.println("right：" + Arrays.toString(num));
                while (left != right && num[left] <= tmp) {
                    left++;
                }
                num[right] = num[left];
                System.out.println("left：" + Arrays.toString(num));
            }
            num[left] = tmp;
            fastSort(num, start, left);
            fastSort(num, left + 1, end);
        }
        return num;
    }

}
